﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Web.Services;
using Netcare.Core;

namespace Netcare.Web.Services
{
    /// <summary>
    /// Summary description for mssql
    /// </summary>
    [WebService(Namespace = "http://www.wicresoft.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class MsSql : System.Web.Services.WebService
    {
        /// <summary>
        /// 获得指定数据库的链接数
        /// </summary>
        /// <param name="dateBaseName">当前要查询的数据库名</param>
        /// <param name="connectionString">数据库连接（"Data Source=服务器;Initial Catalog=数据库;Integrated Security=True"）</param>
        /// <returns>【返回链接个数】 counts</returns>
        [WebMethod]
        public int GetDataBaseSqlConnectionNum(string dateBaseName, string connectionString)
        {
            int counts = 0;
            using (var conn = new SqlConnection(connectionString))
            {
                conn.Open();
                //得到dateBaseName的链接数
                string sql = string.Format("select count(*) from sysprocesses where dbid in (select dbid from sysdatabases where name='{0}')", dateBaseName);
                var comm = new SqlCommand(sql, conn);
                return counts = Convert.ToInt32(comm.ExecuteScalar());

            }
        }

        [WebMethod]
        public string[] GetDataBaseInfo(string dateBaseName, string connectionString)
        {
            List<string> list = new List<string>();

            return list.ToArray();
        }
    }
}
